<?php $this->headScript()->appendFile($this->js('plugins/jquery.blockUI.js'))?>
<script>
$(function(){
    $("#yearSemester, #select-grade").change(function(){
        if ($("#select-grade").val() == '')
            return false;
        $.each($("INPUT[@name='selSubject[]'][type='checkbox']"),function(){
            $(this).attr('checked', false);
        });
        $("#selectForm").submit();
     });

    $("#stage").change(function(){
    	 $("#selectForm").submit();
     });

    $("#start").click(function(){
        if ($("#numbers").val()=='') {
            alert('<?php echo $this->translate("numbers of count cant not empty")?>');
            return false;
        }
        $.blockUI();
        $("#selectForm input[name='act']").val('count');
        $("#selectForm").submit();
    });

    $("#downloadCSV").click(function(){
        $("#selectForm input[name='act']").val('downloadCSV');
        $("#selectForm").submit();
    });

    $("#downloadGroupScore").click(function(){
        $("#selectForm input[name='act']").val('downloadGroupScore');
        $("#selectForm").attr('target','_blank');
        $("#selectForm").submit().removeAttr('target');
        $("#selectForm input[name='act']").val('');
    });

    $("#topTable tbody tr:even").addClass('even');
    $("#topTable tbody tr:odd").addClass('odd');
});
</script>
<style>
#selectTable , #topTable {background: #cce; border-spacing: 1px; margin:5px}
#topTable {padding:2px}
#selectTable tr {background: #ffe}
#selectTable th {padding:3px ; width:40px}
#topTable th {padding:3px; width:40px}
#topTable td {padding:3px; text-align:right}
.even {background-color: #ffe}
.odd {background-color: #eef}
.nowrap {white-space: nowrap; text-align:center}
</style>
<div class="ui-widget">
<form method="post" action="" id="selectForm">
<select name="yearSemester" id="yearSemester">
<?php echo $this->YearSemesterOptions($this->yearSemester,array('order'=>'year DESC'))?>
</select>
<select id="select-grade" name="select-grade">
<option value=""><?php echo $this->translate('select grade ..')?></option>
<?php echo $this->ClassGradeOptions($this->selectGrade)?>
</select>
<?php if ($this->examineSet):?>
<select name="stage" id="stage">
<option value=""><?php echo $this->translate('choose stage ..')?></option>
<?php for($i=1; $i <= $this->examineSet->period; $i++):?>
<option value="<?php echo $i?>" <?php if($i==$this->stage):?>selected<?php endif?> ><?php echo sprintf($this->translate('%dth stage'),$i)?></option>
<?php endfor;?>
<option value="255" <?php if($this->stage==255):?>selected<?php endif?>><?php echo $this->translate('whole stage')?></option>
</select>
<select id="orderKind" name="orderKind">
<option value="<?php echo Score_Model_Statistics::TOP_GRADE_MODEL?>"
 <?php echo Sfs_Html::printSelected(Score_Model_Statistics::TOP_GRADE_MODEL,$this->orderKind)?> ><?php echo $this->translate('top of all grade')?></option>
<option value="<?php echo Score_Model_Statistics::TOP_CLASS_MODEL?>"
 <?php echo Sfs_Html::printSelected(Score_Model_Statistics::TOP_CLASS_MODEL,$this->orderKind)?>><?php echo $this->translate('top of each class')?></option>
</select>
<input type="checkbox" id="plusCount"  name="plusCount" value="1" <?php  Sfs_Html::printChecked($this->plusCount)?>><label for="plusCount"><?php echo $this->translate('usually score counted')?></label>
<input type="checkbox" id="rateCount" name="rateCount"  value="1" <?php  Sfs_Html::printChecked($this->rateCount)?>><label for="rateCount"><?php echo $this->translate('rate counted')?></label>
 , <label for="numbers"><?php echo $this->translate('list numbers')?></label><input type="text"  id="numbers" name="numbers" size="3"  value="<?php echo $this->numbers?>"/>
<?php endif;?>
<?php if ($this->subject):?>
<table id="selectTable" >
<thead>
<tr>
<th rowspan=2><?php echo $this->translate('choose subject')?></th>
<?php foreach($this->subject as $val):?>
<?php foreach($val as $row):?>
<th><?php echo $row['name']?>
</th>
<?php endforeach?>
<?php endforeach?>
<th rowspan=2><input type="button" id="start" value="<?php echo $this->translate('start count')?>" /></th>
</tr>
<tr>
<?php foreach($this->subject as $val):?>
<?php foreach($val as $row):?>
<th><input type="checkbox" name="selSubject[<?php echo $row['subject_sn']?>]" value="1"
<?php if(count($this->selSubject)==0 or isset($this->selSubject[$row['subject_sn']]))Sfs_Html::printChecked(1)?>
/></th>
<?php endforeach?>
<?php endforeach?>
</tr>
</thead>
</table>

<div id="listTopTable">
<?php if ($this->topList):?>
<input type="button" id="downloadCSV" value="<?php echo $this->translate('download csv file')?>" />
<input type="button" id="downloadGroupScore" value="<?php echo $this->translate('download group score')?>" />
<table id="topTable" class="ui-corner-all" >
<thead>
<tr>
<th><?php echo $this->translate('rate')?></th>
<th><?php echo $this->translate('class name')?></th>
<th><?php echo $this->translate('number')?></th>
<th><?php echo $this->translate('student id')?></th>
<th><?php echo $this->translate('student name')?></th>
<?php foreach($this->subject as $val):?>
<?php foreach($val as $row):?>
<?php if (isset($this->selSubject[$row['subject_sn']])):?>
<th><?php echo $row['name']?>
<?php if ($this->rateCount):?>
<br />X<?php echo $row['rate']?>
<?php endif?>
<?php endif?>
</th>
<?php endforeach?>
<?php endforeach?>
<th><?php echo $this->translate('total')?></th>
</tr>
</thead>
<tbody>
<?php foreach ($this->topList as $row):?>
<tr>
<td><?php echo $row['rate']?></td>
<td><?php echo $row['class_sn']?></td>
<td><?php echo $row['number']?></td>
<td><?php echo $row['student_id']?></td>
<td class="nowrap"><?php echo $row['name']?></td>
<?php $subjectArr = unserialize($row['subject_arr'])?>
<?php foreach($this->subject as $val):?>
<?php foreach($val as $row2):?>
<?php if (isset($this->selSubject[$row2['subject_sn']])):?>
<td><?php if (isset($subjectArr[$row2['subject_sn']])) echo $subjectArr[$row2['subject_sn']]?></td>
<?php endif?>
<?php endforeach?>
<?php endforeach?>
<td><?php echo $row['score']?></td>
</tr>
<?php endforeach?>
</tbody>

</table>
<?php endif?>
</div>

<?php endif;?>
<input type="hidden" name="act" />
</form>
</div>